//
//  YZCameraTakePhotoView.m
//  VET
//
//  Created by YZ on 2018/7/16.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZCameraTakePhotoView.h"

@interface YZCameraTakePhotoView ()

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UIView *upView;
@end

@implementation YZCameraTakePhotoView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.upView];
        
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesAction:)];
        [self.upView addGestureRecognizer:tapGes];
        
        self.bgView.layer.cornerRadius = kCurrentDeviceNum(88/2);
        self.upView.layer.cornerRadius = kCurrentDeviceNum(72/2);
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(88), kCurrentDeviceNum(88)));
            make.center.equalTo(self);
        }];
        
        [self.upView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(72), kCurrentDeviceNum(72)));
            make.center.equalTo(self);
        }];
    }
    return self;
}

- (void)tapGesAction:(UITapGestureRecognizer *)ges
{
    if (_delegate && [_delegate respondsToSelector:@selector(takePhotoAction)]) {
        [_delegate takePhotoAction];
    }
}

#pragma mark -- setters && getters

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.layer.masksToBounds = YES;
        _bgView.backgroundColor = kColorWithHexAlpha(0xFFFFFF, 0.6);
    }
    return _bgView;
}

- (UIView *)upView
{
    if (!_upView) {
        _upView = [UIView new];
        _upView.layer.masksToBounds = YES;
        _upView.backgroundColor = kColorWithHex(0xFFFFFF);
    }
    return _upView;
}

@end
